/*
 *      dht22.c:
 *	Simple test program to test the wiringPi functions
 *	Based on the existing dht11.c
 *	Amended by technion@lolware.net
 */

#include <wiringPi.h>

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>

#define MAXTIMINGS 85
static int DHTPIN = 21;

static int off()
{
  pinMode(DHTPIN, OUTPUT);
  digitalWrite(DHTPIN, LOW);
  return 1;
}
static int on()
{
  pinMode(DHTPIN, OUTPUT);
  digitalWrite(DHTPIN, HIGH);
  return 1;
}

int main (int argc, char *argv[])
{
  int status = 0;

  if (argc < 2)
    printf ("usage: %s <pin> (<tries>)\ndescription: pin is the wiringPi pin number\nusing 2 (GPIO 27)\nOptional: tries is the number of times to try to obtain a read (default 100)",argv[0]);
  else
    DHTPIN = atoi(argv[1]);
   

  if (argc == 3)
    status = atoi(argv[2]);

  if (wiringPiSetup () == -1)
    exit(EXIT_FAILURE) ;
	
  if (setuid(getuid()) < 0)
  {
    perror("Dropping privileges failed\n");
    exit(EXIT_FAILURE);
  }
  if (status == 0) {
	  off();
      printf("excute off");
  }else{
	  on();
	  printf("excute on");
  }
  return 0 ;
}